<?php
/**
 * Arquivo da Classe VListaEdicao
 * @author Alan Gustavo Santana Ribeiro <alan@prrn.mpf.gov.br> em 25/08/2008
 * @version 1.0
 * @package gc
 */

/**
 * classe VListaEdicao
 * Classe de Vis�o - Tabula dados para edi��o e exclus�o. Utiliza a Classe
 * VTabala.
 */

class VListaEdicao extends VTabela {
    protected $link = "";
    protected $op = "edit";
    public function setOp($op){
        $this->op = $op;
    }
    public function getOp(){
        return $this->op;
    }

    public function setLink($link){
        $this->link = $link;
    }
    public function getLink(){
        return $link;
    }
	public function getCabecalho(){
		$campos = $this->cr->getCampos();
		$pr = true;
		$html = "\t</tr>\n";
		foreach ($campos as $campo) {
			if($pr){
				$html.= "\t\t<th><input type='checkbox' name='todos' value='todos' id='selecionarTodos' /></th>\n";
				$pr=false;
			} else
				$html .= "\t\t<th>". strtoupper($campo) . "</th>\n";
		}
		return $html;

	}

	public function getDados() {
		$dados 	= $this->cr->getResultados();
		$ln		= "par";
        $html = '';
		foreach ($dados as $linha) {
			$pr		 = true;
			$html	.= "\t<tr class='$ln'>\n";
			foreach ($linha as $reg){
				if($pr){
					$id = $reg;
					$html   .= "\t\t<td><input type='checkbox' name='lstEdicao[]' value='$reg' class='Tabela Checkbox'/></td>";
					$pr = false;
				} else {
					$html .="\t\n";
                                         if($this->editar == true){
                                             $opL = $this->getOp();
                                             $paramExtras = !empty($this->link)?"&{$this->link}":"";
                                             $html .= "\t\t<td><a href='?op={$opL}&id={$id}{$paramExtras}'>$reg</a></td>\n";
                                         }
					$html .="\t\n";

				}

			}
			$html .= "\t</tr>\n";
			$ln = $ln=="par"?"impar":"par";
		}
		return $html;
	}

    public function getTabela(){
        $script = "
       <script type='text/javascript'>
                    $('document').ready(function(){
                        $('#selecionarTodos').click(function(){
                            chk = $('#selecionarTodos').attr('checked');
                            //alert(chk);
                            $('.Tabela.Checkbox').attr('checked',chk);
                        });

                    });
        </script>
        ";
        parent::getTabela();
        $this->tabela .= $script;
        return $this->tabela;
    }
}
?>